package net.mysoft.framework.util;

public class NumberUtil{
	/**
	* 获得阿拉伯数字对应的中文 最大只支持到9千9百九十九亿9千9百九十九万9千9百九十九
	* @param number		要转换的数字
	* @param depth		递归深度,使用时候直接给0即可
	* @return String	数字的中文描述
	*/
	public static String getChinese(String number, int depth) {
		
		if (depth < 0) depth = 0;
		String chs = "";
		String src = number;
		if (src.length() > 4) {
			chs = getChinese(src.substring(0, src.length() - 4), depth + 1)
					+ getChinese(src.substring(src.length() - 4, src.length()),
					depth - 1);
		} else {
			for (int i = 0; i < src.length(); i++) {
				switch (src.charAt(i)) {
					case '0':
						chs = chs + "零";
						break;
					case '1':
						chs = chs + "一";
						break;
					case '2':
						chs = chs + "二";
						break;
					case '3':
						chs = chs + "三";
						break;
					case '4':
						chs = chs + "四";
						break;
					case '5':
						chs = chs + "五";
						break;
					case '6':
						chs = chs + "六";
						break;
					case '7':
						chs = chs + "七";
						break;
					case '8':
						chs = chs + "八";
						break;
					case '9':
						chs = chs + "九";
						break;
				}
				switch (src.length() - 1 - i) {
					case 1: // 十
						chs = chs + "十";
						break;
					case 2: // 百
						chs = chs + "百";
						break;
					case 3: // 千
						chs = chs + "千";
						break;
				}
			}
		}
		if (chs.length() > 0 && chs.lastIndexOf("零") == chs.length() - 1) {
			chs = chs.substring(0, chs.length() - 1);
		}
		if (depth == 1) {
			chs += "万";
		}
		if (depth == 2) {
			chs += "亿";
		}
		return chs;
	}
	
	public static String getChinese(int number, int depth) {
		return getChinese(String.valueOf(number),depth);
	}
	public static void main(String[] args) {
		System.out.println(NumberUtil.getChinese("5555",0));
	}
	
}
